﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RJ.Objects.GameEngine;
using System.Drawing;
using RJ.Euchre.App.Views;
using RJ.Objects.GameRules;

namespace RJ.Euchre.App.Game
{
    public class EuchreGameState : GameState
    {
        private LinkedList<GameView> linkedViewOrder;
        private GameView menu;

        public GameView gameView;
        public EuchreRules gameRules;

        public EuchreGameState(Size clientSize)
            : base(clientSize)
        {
            linkedViewOrder = new LinkedList<GameView>();
            gameRules = new EuchreRules();
            settings = new EuchreSettings();

            menu = new MenuView(this, new SpriteSheet(@"Resources\CardBacks_sm.png"), 4);
            (menu as MenuView).Continue += new ContinueEventHandler(EuchreGameState_Continue);
            gameView = new EuchreTableView(this);

            var node = linkedViewOrder.AddFirst(menu);
            linkedViewOrder.AddAfter(node, gameView);

            Initialize();
        }

        void EuchreGameState_Continue(object sender, GameEventArgs e)
        {
            var node = linkedViewOrder.Find(sender as GameView);

            if (node != null)
            {
                current = node.Next.Value;
                current.Initialize();
            }
        }

        public override void Initialize()
        {
            current = menu;
            gameRules.Initialize();
        }

        public override void KeyboardKeyPressed(System.Windows.Forms.Keys key)
        {
        }
    }
}
